package com.imut.oa.util;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.imut.oa.contant.UserContant;


import java.util.Date;
import java.util.Map;

public class JwtUtil {
    //接受业务数据，生成token并返回
    public static String genToken(String secretKey, long ttlMillis,Map<String, Object> claims){
        return JWT.create()

                .withClaim("claims",claims)
                .withExpiresAt(new Date(System.currentTimeMillis() + ttlMillis))
                .sign(Algorithm.HMAC256(secretKey));
    }
    //接受token，验证token是否有效
    public static Map<String,Object> parseToken(String secretKey,String token){
        return JWT.require(Algorithm.HMAC256(secretKey))
                .build()
                .verify(token)
                .getClaim("claims")
                .asMap();
    }
}
